package com.litongjava.ai.server.padddle.ocr.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.UUID;

@Slf4j
@Component
public class FileUtil {

    public static File getFile(MultipartFile file,String uploadPath) throws IOException {
        // 生成新文件名
        String fileName = UUID.randomUUID() + ".jpg";

        // 创建上传目录
        //TODO:绝对路径后续修改为相对路径
        File uploadDir = new File(uploadPath);
        if (!uploadDir.exists()) {
            uploadDir.mkdirs();
        }
        // 目标文件
        File targetFile = new File(uploadPath + File.separator + fileName);
        // 保存文件
        file.transferTo(targetFile);

        return targetFile;
    }
}
